package com.blood.modules.pregnancy.controller;

import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.core.util.bean.BeanUtil;
import com.blood.core.util.bean.BeanUtils;
import com.blood.modules.pregnancy.dto.req.PregnancyMessagePageReq;
import com.blood.modules.pregnancy.dto.resp.PregnancyMessageInfoResp;
import com.blood.modules.pregnancy.dto.resp.PregnancyMessagePageResp;
import com.blood.modules.pregnancy.service.IPregnancyMessageService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 孕产通知Controller
 *
 * @author daoren
 * @date 2022-11-25 09:11:14
 */
@Api(value = "孕产通知", tags = "孕产通知")
@ApiSort(901)
@RestController
@RequestMapping("/pregnancy/message")
public class PregnancyMessageController {

    /**
     * 孕产通知服务.
     */
    @Autowired
    private IPregnancyMessageService pregnancyMessageService;

    /**
     * 分页查询列表
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "列表-分页")
    public ResponseResult<PageResult<PregnancyMessagePageResp>> pageList(@RequestBody PregnancyMessagePageReq req) {
        return GlobalResultStatus.SUCCESS.toResult().response(pregnancyMessageService.pageList(req));
    }

    /**
     * 查看最新消息.
     *
     * @return 最新消息
     */
    @ApiOperation(value = "查看最新消息")
    @GetMapping(value = "/queryNew")
    public ResponseResult<PregnancyMessageInfoResp> queryNew() {
        return GlobalResultStatus.SUCCESS.toResult().response(BeanUtils.copyProperties(pregnancyMessageService.queryNewInfo(), PregnancyMessageInfoResp.class));
    }

    /**
     * 更改为已读通知.
     *
     * @param id 保存参数
     * @return 添加结果
     */
    @ApiOperation(value = "更改为已读通知")
    @GetMapping(value = "/read")
    public ResponseResult<Void> read(@ApiParam(value = "id", type = "String") @RequestParam("id") String id) {
        pregnancyMessageService.read(id);
        return GlobalResultStatus.SUCCESS.toResult().responseEmptyBody();
    }

    /**
     * 全部已读.
     *
     * @return 添加结果
     */
    @ApiOperation(value = "全部已读")
    @GetMapping(value = "/allRead")
    public ResponseResult<Void> allRead() {
        pregnancyMessageService.allRead();
        return GlobalResultStatus.SUCCESS.toResult().responseEmptyBody();
    }

    /**
     * 清空通知.
     *
     * @return 修改结果
     */
    @ApiOperation(value = "清空通知")
    @GetMapping(value = "/clear")
    public ResponseResult<Void> clear() {
        return pregnancyMessageService.clear();
    }
}
